<template>
  <el-drawer
    title="添加大模型"
    v-model="show"
    size="512px"
    :before-close="handleClose"
    destroy-on-close
    @open="handleOepn"
  >
    <LLMForm :data="formData" ref="formRef" />

    <!-- <el-form ref="formRef" :model="formData" label-width="80px" label-position="left">
      <at-form-group v-model="formData" :json="formJson" />
    </el-form> -->

    <template #footer>
      <el-button @click="show = false">取消</el-button>
      <el-button type="primary" @click="handleSubmit">确定</el-button>
    </template>
  </el-drawer>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessageBox, ElMessage } from 'element-plus'

import http from '@/utils/http'
import LLMForm from './LLMForm.vue'

const show = defineModel({ type: Boolean })
const emits = defineEmits(['submit'])
const props = defineProps({
  data: Object,
})

const formRef = ref(null)
const formData = ref({})

const handleClose = () => emits('update:modelValue', false)
const handleSubmit = () => {
  formRef.value.submit(() => {
    show.value = false
    emits('submit')
  })
  // formRef.value.validate().then(() => {
  //   if (formData.value.id) {
  //     http.put('/hids/llm/config', formData.value).then(() => {
  //       ElMessage.success('修改成功')
  //       show.value = false
  //       emits('submit')
  //     })
  //   } else {
  //     http.post('/hids/llm/config', formData.value).then(() => {
  //       ElMessage.success('添加成功')
  //       show.value = false
  //       emits('submit')
  //     })
  //   }
  // })
}

const handleOepn = () => {
  formData.value = {
    ...props.data,
  }
}
</script>

<style lang="scss" scoped></style>
